﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using V5_EShop._Class;

namespace V5_EShop.Admin.Plus.Picture
{
    public partial class ViewCode : System.Web.UI.Page
    {
        protected string highLighterJs;

        protected void Page_Load(object sender, EventArgs e)
        {
            string filePath = Request.QueryString["objfile"];

            if (File.Exists(filePath))
            {
                string fileExt;
                string fileContent;
                string getEncode;
                string highLighterType = "";

                switch (Path.GetExtension(filePath).ToLower())
                {
                    case ".c":
                    case ".cpp":
                        highLighterType = "cpp";
                        highLighterJs = "shBrushCpp.js";
                        break;
                    case ".cs":
                        highLighterType = "csharp";
                        highLighterJs = "shBrushCSharp.js";
                        break;
                    case ".css":
                        highLighterType = "css";
                        highLighterJs = "shBrushCss.js";
                        break;
                    case ".java":
                    case ".jsp":
                        highLighterType = "java";
                        highLighterJs = "shBrushJava.js";
                        break;
                    case ".js":
                        highLighterType = "javascript";
                        highLighterJs = "shBrushJScript.js";
                        break;
                    case ".php":
                        highLighterType = "php";
                        highLighterJs = "shBrushPhp.js";
                        break;
                    case ".sql":
                        highLighterType = "sql";
                        highLighterJs = "shBrushSql.js";
                        break;
                    case ".vb":
                        highLighterType = "vb";
                        highLighterJs = "shBrushVb.js";
                        break;
                    case ".xml":
                    case ".htm":
                    case ".html":
                    case ".aspx":
                        highLighterType = "xml";
                        highLighterJs = "shBrushXml.js";
                        break;
                }

                new FileManagerProcessor().ReadTextFile(filePath, out fileContent, out getEncode);
                txtHighLighter.Text = fileContent;
                txtHighLighter.CssClass = highLighterType;
            }
            else
            {
                Response.Clear();
                Response.StatusCode = 404;
                Response.StatusDescription = "Not Found";
                Response.Status = "404 Not Found";
                Response.Write("404 Not Found");
                Response.End();
            }
        }
    }
}